﻿using System;
using System.Collections.Generic;
using System.Text;
//new
using DataRecv.models.road;
using System.Collections;

namespace DataRecv.models.device
{
    public class DeviceView
    {
        public DeviceParam deviceparam;
        public RoadParam roadparam;
        public FocusParam focusparam;
        public DeviceView()
        {
            deviceparam = new DeviceParam();
            roadparam = new RoadParam();
            focusparam = new FocusParam();
        }

        /// <summary>
        /// 加载所有设备
        /// </summary>
        /// <returns></returns>
        public static Hashtable GetModels()
        {
            Hashtable ans = new Hashtable();
            try
            {
                List<DeviceParam> deviceparams = DeviceParam.GetModels();
                List<RoadParam> roadparams = RoadParam.GetModels();
                List<FocusParam> focusparams = FocusParam.GetModels();
                if ((deviceparams != null)&&(roadparams!=null))
                {
                    foreach (DeviceParam dp in deviceparams)
                    {
                        DeviceView view = new DeviceView();
                        view.deviceparam = dp;
                        foreach (RoadParam rp in roadparams)
                        {
                            if (rp.roadid == dp.roadid)
                            {
                                view.roadparam = rp;
                                break;
                            }
                        }
                        view.focusparam.ip = dp.ip;
                        if (focusparams != null)
                        {
                            foreach (FocusParam fp in focusparams)
                            {
                                if (dp.ip == fp.ip)
                                {
                                    view.focusparam = fp;
                                    break;
                                }
                            }
                        }
                        ans.Add(dp.ip, view);
                    }
                }
            }
            catch
            {
                ans = null;
            }
            return ans;
        }

    }
}
